#ifndef DATAREPORT_MANAGER_H
#define DATAREPORT_MANAGER_H
#include "timer.h"
#include "syscore.h"
#include "apis.h"
#include "msgcmn.h"
#include "common.h"
#include <vector>
typedef struct tagPERMSGHEADER
{
	long mType;			
	uint16_t dstID;		
	uint16_t srcID;		
	uint16_t msgType;		
	uint16_t msgLength;	
	uint16_t cmdType;
	uint16_t cmdCode;
	uint16_t cmdIndex;
	uint16_t cmdLength;
}PERMSGHEADER,*PPERMSGHEADER;

class WrapperCmdPara
{
public:
    WrapperCmdPara();
    WrapperCmdPara(uint32_t type, uint32_t length, uint8_t* value);
    WrapperCmdPara(uint32_t type, uint8_t value);
    WrapperCmdPara(uint32_t type, int8_t value);
    WrapperCmdPara(uint32_t type, uint16_t value);
    WrapperCmdPara(uint32_t type, uint32_t value);
    WrapperCmdPara(uint32_t type, uint64_t value);
    uint32_t paraType_;
    uint32_t paraLength_;
    uint8_t* value_;

    union
    {
        uint8_t v8;
        int8_t iv8;
        uint16_t v16;
        uint32_t v32;
        uint64_t v64;
    } innerValue;
    
private:
};

#define MsgHandlerPtr MsgHandler::ptr()
class MsgHandler
{
public:
    static MsgHandler *ptr();
    bool initialize();
    bool uninitialize();
    void HandleMsg();
    void reponseToModule(uint16_t dstId, uint16_t msgType, uint16_t cmdType, uint16_t cmdCode, uint16_t cmdIndex, const std::vector<WrapperCmdPara>& paraArray);
    void timerStart();
    
    
private:
    MsgHandler();
    MsgHandler(const MsgHandler&);
    MsgHandler& operator=(const MsgHandler&);
    int32_t queue_rx;
    int32_t queue_tx;
    bool initMsgQueue();    
    bool initialized;
    static MsgHandler *InstanceM;
    uint8_t recvMsgBuf[8192];
    PERMSGHEADER *msgHeader;
    std::vector < WrapperCmdPara > reponseParas;
    void handleGetDataTmOut();
    TimerElement<MsgHandler> getDataTimeOut_;
};

inline MsgHandler *MsgHandler::ptr()
{
    MsgHandler *Pointer = InstanceM;
    if (InstanceM == NULL)
    {
        Pointer = InstanceM  = new MsgHandler();
    }
    
    return Pointer;
}
#endif


